from django.contrib.sitemaps import Sitemap
from django.urls import reverse

from BaseWeb.models import DetailPage
class IndexPageSitemap(Sitemap):
    changefreq = 'daily'
    priority = 1.0

    def items(self):
        return ['index', ]

    def location(self, item):
        return reverse(item)

    def get_urls(self, page=1, site=None, protocol=None):
        urls = super().get_urls(page, site, protocol)
        for url in urls:
            url['mobile'] = 'pc,mobile'
        return urls



class DetailPageSitemap(Sitemap):
    changefreq = 'daily'
    priority = 0.9

    def items(self):
        return DetailPage.objects.all()
    def location(self, item):
        return reverse('detail',kwargs={'page': item.pageid})
    def lastmod(self, item):
        return item.date
    def get_urls(self, page=1, site=None, protocol=None):
        urls = super().get_urls(page, site, protocol)
        for url in urls:
            url['mobile'] = 'pc,mobile'
        return urls
    # // 看这里，增加一个mobile字段，按照自己页面的情况，选择htmladapt / mobile / pc。

